package com.tqyan.model.enums;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * @description 论文支付状态
 * <p> <功能详细描述> </p>
 *
 * @author 陈晨
 * @date 2023/4/11 17:51
 */
@Getter
@AllArgsConstructor
public enum PaperPayStatusEnum {

    UNPAID(0, "未支付"),
    PAID(1, "已支付"),
    ;

    private final int value;
    private final String desc;

    public static PaperPayStatusEnum get(Integer value) {
        if (null == value) {
            return null;
        }
        return Arrays.stream(PaperPayStatusEnum.values())
                .filter(e -> e.value == value).findFirst().orElse(null);
    }

    public static PaperPayStatusEnum getByDesc(String desc) {
        if (StringUtils.isBlank(desc)) {
            return null;
        }
        return Arrays.stream(PaperPayStatusEnum.values())
                .filter(e -> e.desc.equals(desc)).findFirst().orElse(null);
    }

    public static Integer getValueByDesc(String desc) {
        PaperPayStatusEnum getEnum = Arrays.stream(PaperPayStatusEnum.values())
                .filter(e -> e.desc.equals(desc)).findFirst().orElse(null);
        if (null == getEnum) {
            return null;
        }
        return getEnum.getValue();
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }

}
